package com.linkai.JUC._11_stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: Stream 流式计算    
 *               筛选：
 *               1. ID必须是偶数
 *               2. 年龄大于23岁
 *               3. 用户名转化为大写字母
 *               4. 用户名字母着排序
 *               5. 只输出一个用户
 * @Author: 林凯
 * @Date: 2021/10/25 17:19
 */
public class Demo01 {
    public static void main(String[] args) {
        User u1 = new User(1, "a", 21);
        User u2 = new User(2, "b", 22);
        User u3 = new User(3, "c", 23);
        User u4 = new User(4, "d", 24);
        User u5 = new User(5, "e", 25);

        // 集合就是存储
        List<User> list = Arrays.asList(u1, u2, u3, u4, u5);

        // 计算交给 Stream
        // lambda表达式，链式编程，函数式接口，Stream流式计算
        list.stream()
                .filter((u)->{return u.getId() %2 == 0;})
                .filter((u)->{return u.getAge() > 23;})
                .map((u)->{return u.getName().toUpperCase();})
                .sorted((uu1, uu2)->{return uu2.compareTo(uu1);})
                .limit(1)
                .forEach(System.out::println);
    }
}

@Data
@NoArgsConstructor
@AllArgsConstructor
class User {
    private int id;
    private String name;
    private int age;
}
